Micron Document
Fox's Git Mirrors

Node / rns-mirrors / Reticulum-Go.git / files / pkg / interfaces / https_leak_test.go

Displaying Raw • Download

pkg/interfaces/https_leak_test.go 61af5556362c8bdf7c09a1c01bc84f81629f281b (61af5556) Text, 1.08 KB

// SPDX-License-Identifier: Apache-2.0
// Copyright (c) 2024-2026 Quad4.io

//go:build !js

package interfaces

import (
"runtime"
"testing"
"time"
)

func TestHTTPSNoGoroutineLeak(t *testing.T) {
runtime.GC()
baseline := runtime.NumGoroutine()

for range 20 {
port := freeHTTPSPort(t)
srv, err := NewHTTPSServerInterface("https_leak_srv", "127.0.0.1", port, HTTPSServerOptions{
LongPoll: 200 * time.Millisecond,
})
if err != nil {
t.Fatal(err)
}
if err := srv.Start(); err != nil {
t.Fatal(err)
}
port = listenHTTPSPort(t, srv)
cli, err := NewHTTPSClientInterfaceWithRetries("https_leak_cli", "127.0.0.1", port, true, 5, HTTPSClientOptions{
LongPoll: 200 * time.Millisecond,
})
if err != nil {
_ = srv.Stop()
t.Fatal(err)
}
waitOnline(t, cli, 5*time.Second)
_ = cli.Send([]byte{0x50, 0x01}, "")
_ = cli.Stop()
_ = srv.Stop()
}

time.Sleep(150 * time.Millisecond)
runtime.GC()
final := runtime.NumGoroutine()
if final > baseline+12 {
t.Errorf("possible goroutine leak: baseline=%d final=%d", baseline, final)
}
}

Served by rngit 1.5.2 - Generated in 0.02s